package kr.lim.hy.clicker.util;

import java.util.Calendar;

import kr.lim.hy.clicker.R;
import kr.lim.hy.clicker.R.raw;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Vibrator;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

public class EffectUtil {
	private static SoundPool sound_pool;
	private static int sound_beep;

	/**
	 * 진동 나는부분
	 */
	public static void vibrator(Context context) {

		Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
		long milliseconds = 1000;
		vibrator.vibrate(milliseconds);

	}

	/**
	 * 효과음 설정
	 */
	public static void sound_init(Context context) {

		sound_pool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
		sound_beep = sound_pool.load(context, R.raw.click_1, 1);

	}

	/**
	 * 효과음 재생
	 */
	public static void sound_play() {
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {

			e.printStackTrace();
		}

		sound_pool.play(sound_beep, 1, 1, 0, 0, 1);

	}

	/**
	 * 효과음 재생
	 */
	public static void sound_play_nodelay() {

		sound_pool.play(sound_beep, 1, 1, 0, 0, 1);

	}
/*
	*//**
	 * 0 사용 3,4사용 /** notification_id 0:|주기보고 등록,취소| notification_id 1: power on
	 * notification_id 2: power off notification_id 3:안심존 진입 notification_id
	 * 4:안심존 진출 notification_id 5: 주기보고 notification_id 6: 현위치 notification_id
	 * 7:잘못측위
	 * 
	 * 6은 아래 따로잇음
	 * 
	 * 인텐트 없엇던 경우
	 * 
	 * @param context
	 * @param notification_id
	 *            noti아이디
	 * @param mMdn
	 * @param message
	 *            띄울 메시지
	 *//*
	public static void generateNotification(Context context, int notification_id, String mMdn, String message) {
		Boolean autoCancle;
		Intent notificationIntent = null;
		Calendar cal = Calendar.getInstance();
		long when = cal.getTimeInMillis();

		String title = context.getString(R.string.app_name);

		NotificationManager notificationManager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);

		//TODO 혹시모르니 1,2,3,4,5이렇게 다넣어놧는데 혹시몰라서 이렇게만듬 나중에 수정해서 필요없는거 지워야함
		if (notification_id == 0 || notification_id == 1 || notification_id == 2) {//0주기보고등록,1poweron,2poweroff
			notificationIntent = new Intent(context, UserDetail.class).putExtra("MDN", mMdn).setFlags(
					Intent.FLAG_ACTIVITY_CLEAR_TOP);//계속 싸여잇어서
		} else if (notification_id == 3 || notification_id == 4) {//3안심존진입,4진출
			notificationIntent = new Intent(context, FindLocationHistory.class).putExtra("MDN", mMdn)
					.putExtra("NOTIFY", "Y").setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//경로설정
			//안심존 들어갈때 intent에서 notify를보냄

		} else if (notification_id == 5) {//5주기보고
			notificationIntent = new Intent(context, FindLocation.class).putExtra("MDN", mMdn);//경로설정 //이건안쓰니깐 안넣음
		} else if (notification_id == 7) {
			Log.i("alal", "" + mMdn);
			notificationIntent = new Intent(context, UserDetail.class).putExtra("MDN", mMdn).setFlags(
					Intent.FLAG_ACTIVITY_CLEAR_TOP);
		}

		PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
				PendingIntent.FLAG_UPDATE_CURRENT);
		if (notification_id == 0) {//주기보고일땐 안죽어야 하니깐
			autoCancle = false;
		} else {
			autoCancle = true;
		}

		Notification notification = NotificationFactory(context, title, when, message, intent, autoCancle);

		notificationManager.notify(notification_id, notification);

	}

	*//**
	 * 이미 인텐트 값을 만들어 논 상황이라 이거하나 더만들엇음..
	 * 
	 * @param context
	 * @param intent
	 * @param notification_id
	 * @param mMdn
	 * @param message
	 *//*
	public static void generateNotification(Context context, PendingIntent intent, int notification_id, String mMdn,
			String message) {

		Calendar cal = Calendar.getInstance();

		long when = cal.getTimeInMillis();

		NotificationManager notificationManager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);

		String title = context.getString(R.string.app_name);

		Notification notification;
		notification = NotificationFactory(context, title, when, message, intent, true);
		notificationManager.notify(notification_id, notification);

	}

	*//**
	 * 노티피케이션 취소
	 * 
	 * @param context
	 * @param notification_id
	 *//*
	public static void cancelNotification(Context context, int notification_id) {

		NotificationManager notificationManager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);

		notificationManager.cancel(notification_id);
	}

	*//**
	 * notification 설정값
	 * 
	 * @param context
	 * @param title
	 *            제목
	 * @param when
	 *            시간
	 * @param message
	 *            내용
	 * @param pintent
	 *            pendingIntent값
	 * @param setAuto
	 *            자동삭제되는지 안되는지
	 * @return
	 *//*
	private static Notification NotificationFactory(Context context, String title, long when, String message,
			PendingIntent pintent, Boolean setAuto) {
		Notification notification;

		NotificationCompat.Builder value;
		value = new NotificationCompat.Builder(context).setPriority(NotificationCompat.PRIORITY_DEFAULT)
				.setAutoCancel(setAuto).setSmallIcon(R.drawable.map_icon_01).setContentTitle(title).setWhen(when)
				.setContentText(message);
		if (setAuto) {//0 주기보고 
			value.setLights(Color.YELLOW, 500, 500);
		} else {//나머지 notification들
			value.setOngoing(true);//지우기 눌러도 안지워짐
		}
		value.setContentIntent(pintent);
		notification = value.build();

		return notification;

	}*/
}
